home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / text / edit / BareED.lha / BareED / source / CpyLib.asm < prev    next >
Assembly Source File  |  1997-02-07  |  6KB  |  288 lines

  1. *******************************************************************
  2. *:ts=15
  3. *:fo=helvetica,13
  4. *
  5. *:ts=22
  6. *:fo=times,15
  7. *
  8. *:ts=10
  9. *:fo=diamond,12
  10. *
  11. *:ts=15
  12. *:fo=ruby,15
  13. *
  14. ** or any fixed-width-font, e.g.
  15. *:ts=11
  16. *:fo=excel,11
  17. *
  18. *
  19. *
  20. * TxtCharCopyA()
  21. *
  22. * This routine was written as a replacement for the stuff
  23. * done in ANSI-C for "BareED".
  24. *
  25. * This routine can be used to copy overlayed, whilst non-
  26. * overlayed copying is supported, too.  It's more than 100%
  27. * faster than its eqivalent (byte-copy) in ANSI-C.
  28. * Does not require a MC68020  or higher or other specific
  29. * stuff, runs with a plain MC68000.
  30. *
  31. * Copy-mode selected within routine; there are a couple of
  32. * it avaiable.
  33. *
  34. * Calling convention:
  35. *
  36. *    TxtCharCopyA( source-addr, dest-addr, length);
  37. * void    TxtCharCopyA( char *, char *, ULONG)
  38. *
  39. * IMPROVEMENTS:
  40. *    MEMORY ACCESS DRASTICALLY REDUCED
  41. *    MUCH FASTER ON A 68020 OR WHEN CACHES ARE DISABLED
  42. *    DRASTICALLY SHORTENED
  43. *    OPTIMIZED FOR 32BIT CPUs
  44. *
  45. *    Can now be assembled using a68k.
  46. *
  47. *
  48. * Copyright 1996/97/98/99 Jörg van de Loo
  49. *
  50. * $VER: TxtCharCopyA 2.0 (07.02.1997)
  51. *
  52.  
  53.     IFD        __G2        ; HiSoft Devpac Amiga assembler?
  54.     OPT        L+        ; Create link-able code
  55.     IDNT        'cpylib.asm'
  56.     MACHINE        MC68000        ; Processor
  57.     OUTPUT        cpylib.lib        ; Where to store object?
  58.     ENDC
  59.  
  60.     XDEF    _TxtCharCopy
  61.     XDEF    _TxtCharCopyA
  62.  
  63.     include    exec/execbase.i
  64.  
  65.     SECTION TEXT,CODE
  66.     dc.b    'TXTCHARCOPY 2.0 © COPYRIGHT 1996-99 J.v.d.Loo'
  67.     CNOP    0,4
  68. *
  69. ** C-entry point
  70. *
  71. _TxtCharCopy
  72.     movem.l    4(sp),A0-A1
  73.     move.l    12(sp),D0
  74. *
  75. ** Source, Destination, size - calling convention "CopyMem()" alike
  76. *
  77. _TxtCharCopyA
  78.     movem.l    D2-D6/A2,-(sp)
  79.  
  80.     moveq    #24,D3        ; Shif-values...
  81.     moveq    #8,D4
  82.  
  83.     cmpa.l    A1,A0
  84.     bhi.w    _ForwardCopy    ; Ascend copy
  85.  
  86.     move.l    A0,D1        ; Check if we're going to
  87.     add.l    D0,D1        ; copy 'overlayed'
  88.     cmp.l    A1,D1
  89.     bls.w    _ForwardCopy    ; Ascend copy
  90.  
  91. * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  92.  
  93. _ReverseCopy            ; Descend copy
  94.     lea    0(A0,D0.l),A0
  95.     lea    0(A1,D0.l),A1
  96.  
  97.     cmpi.l    #32,D0        ; At least 33 bytes to copy?
  98.     bls.w    .rbytecpy
  99.  
  100.     move.l    A0,D1
  101.     andi.b    #1,D1
  102.     beq.s    .rsrceven        ; Source even
  103.  
  104. * --------------------------------- *
  105. .rsrcodd
  106.     move.l    A1,D1
  107.     andi.b    #1,D1
  108.     bne.s    .rbothodd
  109.  
  110. .rscrOddDestEven
  111. * ---- Source is odd, destination is even --- *
  112. .sode
  113.     movea.l    (4).w,A2        ; 2478 0004 instead of 2479 0000 0004, Zero-Page = word addressing mode
  114.     move.w    AttnFlags(A2),D1
  115.     andi.w    #AFF_68020!AFF_68030!AFF_68040!AFF_68060,D1
  116.     bne.s    .rbotheven        ; Don't care about the limits of the 68000/08/10/12
  117.  
  118.     move.l    D0,D2        ; Amount
  119.     andi.l    #-4,D2        ; Modulo 4
  120.     sub.l    D2,D0        ; Compute rest
  121.     lsr.l    #2,D2        ; Through 4 (number of longs)
  122.     subq.l    #1,D2        ; 'Cause of 'Carry'
  123.  
  124.     moveq    #0,D1        ; No conflicts, please
  125.     move.b    -(A0),D1        ; Get the even byte    [ ___e ]
  126. .sode1
  127.     move.l    -(A0),D5        ; Get the even long    [ abcd ]
  128.     move.l    D5,D6        ; Save it for later    [ abcd ]
  129.     lsl.l    D4,D5        ; <<8        [ bcd_ ]
  130.     lsr.l    D3,D6        ; >>24        [ ___a ]
  131.     or.l    D1,D5        ; Join...        [ bcde ]
  132.     move.l    D5,-(A1)        ; Store longword    [ bcde ]
  133.     move.b    D6,D1        ; D1 (byte)    [ ___a ]
  134.     subq.l    #1,D2        ; Decrease number of loops
  135.     bcc.s    .sode1        ; If there is a rest...
  136.     addq.l    #1,A0        ; One too far...
  137.     bra.s    .rbytecpy
  138.  
  139. .rbothodd
  140. * ---- Source is odd, destination is odd --- *
  141.     move.b    -(A0),-(A1)
  142.     subq.l    #1,D0        ; Now both even!
  143.  
  144. * ---- Source is even, destination is even --- * \\\\ Or we have CPU that can handle 32 bit addresses ////
  145. .rbotheven
  146.     move.l    D0,D2        ; Amount
  147.     andi.l    #-32,D2        ; Modulo 32
  148.     sub.l    D2,D0        ; Compute rest
  149.     lsr.l    #5,D2        ; Through 32 (number of longs)
  150.     subq.l    #1,D2        ; 'Cause of 'Carry'
  151. .sede
  152.     move.l    -(A0),-(A1)
  153.     move.l    -(A0),-(A1)
  154.     move.l    -(A0),-(A1)
  155.     move.l    -(A0),-(A1)
  156.  
  157.     move.l    -(A0),-(A1)
  158.     move.l    -(A0),-(A1)
  159.     move.l    -(A0),-(A1)
  160.     move.l    -(A0),-(A1)
  161.  
  162.     subq.l    #1,D2        ; Stored 32 bytes
  163.     bcc.s    .sede        ; A rest?
  164.     bra.s    .rbytecpy
  165.  
  166. * --------------------------------- *
  167. .rsrceven
  168.     move.l    A1,D1
  169.     andi.b    #1,D1
  170.     beq.s    .rbotheven
  171.  
  172. .rsrcEvenDestOdd
  173. * ---- Source is even, destination is odd --- *
  174. .sedo
  175.     move.b    -(A0),-(A1)
  176.     subq.l    #1,D0
  177.     bra.s    .sode        ; Now source odd, destination even!
  178.  
  179. * ---- Check for rest of characters to copy --- *
  180. .rbytecpy
  181.     tst.b    D0
  182.     beq.s    .rdone
  183.  
  184. .rbytecpyLoop
  185.     move.b    -(A0),-(A1)
  186.     subq.b    #1,D0
  187.     bne.s    .rbytecpyLoop
  188. .rdone
  189.     bra.w    _TxtCharCopyDone
  190.  
  191. * %%%%%%%%%%%%%%%%%%%%%%%%%%%
  192.  
  193. _ForwardCopy
  194.     cmpi.l    #32,D0        ; At least 33 bytes to copy?
  195.     bls.s    .fbytecpy
  196.  
  197.     move.l    A0,D1
  198.     andi.b    #1,D1
  199.     beq.s    .fsrceven        ; Source even
  200.  
  201. * --------------------------------- *
  202. .fsrcodd
  203.     move.l    A1,D1
  204.     andi.b    #1,D1
  205.     bne.s    .fbothodd
  206.  
  207. .fscrOddDestEven
  208. * ---- Source is odd, destination is even --- *
  209. .fsode
  210.     movea.l    (4).w,A2
  211.     move.w    AttnFlags(A2),D1
  212.     andi.w    #AFF_68020!AFF_68030!AFF_68040!AFF_68060,D1
  213.     bne.s    .fbotheven        ; Don't care about the limit of the 68000
  214.  
  215.     move.l    D0,D2        ; Amount
  216.     andi.l    #-4,D2        ; Modulo 4
  217.     sub.l    D2,D0        ; Compute rest
  218.     lsr.l    #2,D2        ; Through 4 (number of longs)
  219.     subq.l    #1,D2        ; 'Cause of 'Carry'
  220.  
  221.     move.b    (A0)+,D1        ; The odd byte    [ ><>a ]
  222. .fsode1
  223.     lsl.l    D3,D1        ; <<24        [ a___ ]
  224.     move.l    (A0)+,D5        ; The even long    [ bcde ]
  225.     move.b    D5,D6        ; The odd byte    [ ><>e ]
  226.     lsr.l    D4,D5        ; >>8        [ _bcd ]
  227.     or.l    D5,D1        ; Join...        [ abcd ]
  228.     move.l    D1,(A1)+        ; Store longword    [ abcd ]
  229.     move.b    D6,D1        ; D1 (byte)    [ ><>e ]
  230.     subq.l    #1,D2        ; Decrease number of loops
  231.     bcc.s    .fsode1        ; If there is a rest...
  232.     subq.l    #1,A0        ; One too far...
  233.     bra.s    .fbytecpy
  234.  
  235. .fbothodd
  236. * ---- Source is odd, destination is odd --- *
  237.     move.b    (A0)+,(A1)+
  238.     subq.l    #1,D0
  239.  
  240. * ---- Source is even, destination is even --- * \\\\ Or we have CPU that can handle 32 bit addresses ////
  241. .fbotheven
  242.     move.l    D0,D2        ; Amount
  243.     andi.l    #-32,D2        ; Modulo 32
  244.     sub.l    D2,D0        ; Compute rest
  245.     lsr.l    #5,D2        ; Through 32 (number of longs)
  246.     subq.l    #1,D2        ; 'Cause of 'Carry'
  247. .fsede
  248.     move.l    (A0)+,(A1)+
  249.     move.l    (A0)+,(A1)+
  250.     move.l    (A0)+,(A1)+
  251.     move.l    (A0)+,(A1)+
  252.  
  253.     move.l    (A0)+,(A1)+
  254.     move.l    (A0)+,(A1)+
  255.     move.l    (A0)+,(A1)+
  256.     move.l    (A0)+,(A1)+
  257.  
  258.     subq.l    #1,D2        ; Stored 32 bytes?
  259.     bcc.s    .fsede        ; A rest?
  260.     bra.s    .fbytecpy
  261.  
  262. * --------------------------------- *
  263. .fsrceven
  264.     move.l    A1,D1
  265.     andi.b    #1,D1
  266.     beq.s    .fbotheven
  267.  
  268. .fsrcEvenDestOdd
  269. * ---- Source is even, destination is odd --- *
  270.     move.b    (A0)+,(A1)+
  271.     subq.l    #1,D0
  272.     bra.s    .fsode
  273.  
  274. .fbytecpy
  275.     tst.b    D0
  276.     beq.s    .fdone
  277. .fbytecpyLoop
  278.     move.b    (A0)+,(A1)+
  279.     subq.b    #1,D0
  280.     bne.s    .fbytecpyLoop
  281. .fdone
  282.  
  283. * --------------------------------- *
  284. _TxtCharCopyDone
  285.     movem.l    (sp)+,D2-D6/A2
  286.     rts
  287.  
  288.     END